﻿// -----------------------------------------------------------------------
// <copyright file="DataReaderTransferTask.cs" company="">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace Dhgms.TplHelper.Model.TaskHelper
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    using Dhgms.DataManager.Model.Helper.Database;
    using Dhgms.TplHelper.Controller.Task;
    using Dhgms.TplHelper.Model.DataReaderConsumer;
    using Dhgms.TplHelper.Model.DataReaderProducer;
    using Dhgms.TplHelper.Model.Info;
    using Dhgms.TplHelper.Model.Info.TaskResult;

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public abstract class DataReaderTransferTaskHelper<TDataReaderProducer, TDataReaderConsumer, TTaskResultClass> : ReportableCountTaskHelper<TTaskResultClass>
        where TDataReaderProducer : IDataReaderProducer
        where TDataReaderConsumer : IDataReaderConsumer
        where TTaskResultClass : TaskResultBase, IReportableCount, new()
    {
        /// <summary>Initializes a new instance of the <see cref="DataReaderTransferTaskHelper{TDataReaderProducer,TDataReaderConsumer,TTaskResultClass}"/> class.</summary>
        /// <param name="name">The name.</param>
        protected DataReaderTransferTaskHelper(string name)
            : base(name)
        {
        }

        /// <summary>
        /// The OnProcess event for doing the donkey work
        /// </summary>
        protected override long OnProcess()
        {
            var producer = GetProducer();
            var consumer = GetConsumer();

            return producer.ProduceAndConsume(consumer.DataReaderAction);
        }

        /// <summary>
        /// Gets the producer.
        /// </summary>
        /// <returns>The producer</returns>
        protected abstract TDataReaderProducer GetProducer();

        /// <summary>
        /// Gets the consumer.
        /// </summary>
        /// <returns>The consumer</returns>
        protected abstract TDataReaderConsumer GetConsumer();
    }
}
